package com.han.fu.api.business.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.han.fu.api.business.model.ao.ChannelAddAo;
import com.han.fu.api.business.model.ao.ChannelDeleteAo;
import com.han.fu.api.business.model.ao.ChannelPageAo;
import com.han.fu.api.business.model.ao.ChannelUpdateAo;
import com.han.fu.api.business.model.vo.ChannelInfoVo;
import com.han.fu.api.business.model.vo.ChannelVo;
import com.han.fu.api.business.service.IChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 渠道接口
 *
 * @author: star
 * @date: 2021-08-05
 */
@RestController
public class ChannelController {

    @Autowired
    IChannelService iChannelService;

    /**
     * 渠道分页查询
     *
     * @param ao 分页查询条件
     * @return Page<ChannelVo> 分页数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/channel/page")
    public Page<ChannelVo> queryChannelPage(@Validated @RequestBody ChannelPageAo ao) {
        return iChannelService.queryChannelPage(ao);
    }

    /**
     * 渠道明细查询
     *
     * @param id 主键
     * @return ChannelInfoVo 明细
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @GetMapping("/channel/detail")
    public ChannelInfoVo queryChannelDetail(@NotNull(message = "ID不能为空") @RequestParam String id) {
        return iChannelService.queryChannelDetail(id);
    }

    /**
     * 渠道新增数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/channel/add")
    public void addChannel(@Validated @RequestBody ChannelAddAo ao) {
        iChannelService.addChannel(ao);
    }

    /**
     * 渠道修改数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/channel/update")
    public void updateChannel(@Validated @RequestBody ChannelUpdateAo ao) {
        iChannelService.updateChannel(ao);
    }

    /**
     * 渠道删除数据
     *
     * @param ao 数据
     */
    @PreAuthorize("hasRole('tourist') OR hasRole('member') OR hasRole('admin')")
    @PostMapping("/channel/delete")
    public void deleteChannel(@Validated @RequestBody ChannelDeleteAo ao) {
        iChannelService.deleteChannel(ao);
    }

}